<?php
namespace Home\Controller;
use Think\Controller;

class SearchController extends Controller {
	public function search() {
		if (I('post.searchText')) {
			// 获得表单查询条件
			$species = I('post.searchSpecies');
			$field = I('post.searchField');
			$strWord = I('post.searchText');


			$condition = array();
			$condition['species'] = $species;

			if ($strWord == '-') {
				$condition['location|identifier'] = $strWord;
			}
			else {
				$word = explode(',', $strWord);
				foreach ($word as $key => $value) {
					$array[$key] = (trim($value));
				}

				$condition[$field] = array("in" ,$array);
			}
			$whichTag = 0;
			$this->assign("whichTag", $whichTag);
			$this->assign("species", $species);
			$this->assign("field", $field);
			$this->assign("word", $strWord);

			// $result = M('search')->where($condition)->select(false);
			// var_dump($result);
			if ($result = M('search')->where($condition)->select()){
				$count = sizeof($result);
				$this->assign('result', $result);
				// var_dump($result);
			}
			else {
				$count = 0;
				// var_dump($result);
			}

			if (!empty($_SESSION)) {
				// var_dump($_SESSION);
				$condition = 1;
				$this->assign('username', $_SESSION['username']);
			}
			else {
				$condition = 0;
			}
			$this->assign('condition', $condition);
			$this->assign('count', $count);
			$this->display();
		}
	}

	public function uploadResult() {
		if (I('get.species')) {
			// 保留用于显示提交后的结果
			// $species = I('get.species');
			$species = I('get.species');
			$gene = I('get.gene');
			$forwardprimer = I('get.forwardprimer');
			$reverseprimer = I('get.reverseprimer');
			// $result = unserialize(base64_decode(I('get.result')));
			$result = unserialize(base64_decode(I('get.result')));

			// var_dump($result);
			if (!empty($_SESSION)) {
				// var_dump($_SESSION);
				$condition = 1;
				$this->assign('username', $_SESSION['username']);
			}
			else {
				$condition = 0;
			}
			$whichTag = 3;
			$this->assign('whichTag', $whichTag);
			$this->assign('condition', $condition);
			$this->assign('species', $species);
			$this->assign('gene', $gene);
			$this->assign('forwardprimer', $forwardprimer);
			$this->assign('reverseprimer', $reverseprimer);
			$this->assign('result', $result);
			$this->display();
		}
	}
}

?>
